subroutine histogram_f(nlimits, xlimits, nvalues, xvalues, histo)

    use iasing_osse, only: &
        JPI4,       &
        JPR4

    implicit none
    ! Arguments
    integer(JPI4), intent(in)   :: nlimits
    real(JPR4), intent(in)      :: xlimits(nlimits)
    integer(JPI4), intent(in)   :: nvalues
    real(JPR4), intent(in)      :: xvalues(nvalues)
    integer(JPI4), intent(out)  :: histo(0:nlimits)

    ! Internal variables
    integer :: jv, jh


    ! iasing_osse includes
    include 'dichotom_f.interface'

    ! Subroutine Body
    histo = 0

    do jv = 1, nvalues
        jh = dichotom_f(nlimits, xlimits, xvalues(jv))
        if (jh.gt.0 .and. jh.lt.nlimits) then 
            histo(jh) = histo(jh)+1
        else if (jh.eq.-1) then
            histo(0) = histo(0)+1
        else if (jh.eq.-2) then
            histo(nlimits) = histo(nlimits)+1
        else
            print*, "Histogram subroutine. Error in dichotom_f"
        endif
    enddo


end subroutine histogram_f
